package com.ece400.abrc;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class Debug extends Activity {
	
	SeekBar seekbar_x, seekbar_y;
	TextView textview_x,textview_y;
	int x_val;
	int y_val;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.debug);
		
		x_val = y_val = 0;
		
		seekbar_x = (SeekBar)findViewById(R.id.seekbarX);
		seekbar_y = (SeekBar)findViewById(R.id.seekbarY);
		textview_x = (TextView)findViewById(R.id.txtX);
		textview_y = (TextView)findViewById(R.id.txtY);
		
		seekbar_x.setMax(256);
		seekbar_x.setProgress(0);
		seekbar_x.setOnSeekBarChangeListener(seekbarListener);
		
		seekbar_y.setMax(256);
		seekbar_y.setProgress(0);
		seekbar_y.setOnSeekBarChangeListener(seekbarListener);
	
		RobotConnection.NewDebugXY(0,0);
	}
	
	private SeekBar.OnSeekBarChangeListener seekbarListener = new SeekBar.OnSeekBarChangeListener() {
		@Override
		public void onStopTrackingTouch(SeekBar arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onStartTrackingTouch(SeekBar arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onProgressChanged(SeekBar the_bar, int progress, boolean from_user) {
			// TODO Auto-generated method stub
			if(the_bar == seekbar_x){
				//x updated
				x_val = progress;
				textview_x.setText("PWM 13,14: "+ x_val);
			}else{
				//y updated
				y_val = progress;
				textview_y.setText("PWM 15,16: "+ y_val);
			}
			RobotConnection.NewDebugXY(x_val,y_val);
		}
	};
	
	@Override
	protected void onStop(){
		RobotConnection.NewDebugXY(0,0);
		super.onStop();
	}
}